<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        /**
         * 支付总单 可能含一个或多个子单
         * 由于 火车+飞机中转时，飞机票可单独支付
         * 改签时 新订单也可单独支付
         */
        Schema::create('order_pay', function (Blueprint $table) {
            $table->id();
            $table->uuid('user_id')->comment('用户');
            $table->string('trip_id')->comment('行程id');
            $table->string('pay_title', 127)->comment('支付标题');
            $table->string('pay_sn', 32)->comment('支付单号');
            $table->string('trade_sn')->default('')->comment('支付流水号,支付后才知道');
            $table->string('pay_type')->default(1)->comment('支付类型 1 微信支付');
            $table->unsignedDecimal('pay_amount', 10, 2)->comment('总支付金额');
            $table->unsignedDecimal('real_amount', 10, 2)->default(0)->comment('实际支付金额,支付后才知道');
            $table->unsignedTinyInteger('pay_state')->default(0)->comment('支付状态 0待支付 1已支付 3已取消 2 失败');
            $table->string('trade_desc')->default('')->comment('交易描述');
            $table->string('cancel_reason')->default('')->comment('取消原因');
            $table->string('failed_reason')->default('')->comment('失败原因');
            $table->string('mchid', 32)->default('')->comment('支付商戶id');
            $table->string('appid', 32)->default('')->comment('appid');
            $table->string('business_type')->default(10)->comment('业务类型 10 下单, 11 改签 ,20  抢票 ,21 编辑抢票任务');
            $table->timestamps();
            $table->unique('pay_sn', 'unique_paysn');
            $table->index(['trip_id', 'user_id'], 'idx_trip');
            $table->index(['pay_sn', 'user_id'], 'idx_pay_user');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('order_pay');
    }
};
